<?php

########################################################################################
# Empresa :     Tecnopac Informatica;                                                  #
# Autor:        Deiverson Pacheco;                                                     #
# Data Criação: 18/12/2010;                                                            #
########################################################################################
session_start();
header("Cache-control: private");
include_once("../../includes/session.php");


//Linha para formatação de caracteres com acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);

//======================================================================================
//==> Include obrigatórias no script
//======================================================================================
include_once('../../includes/classes/class.TemplatePower.php');
include_once('../../includes/classes/class.Conexao.php');
include_once('../../includes/classes/class.Geral.php');

//======================================================================================
//==> Inicializar Classes
//======================================================================================
$not  = new Persist;
$data = new getData;
$cor  = new ColorTr;
$util = new Util;
$vld  = new ValidarDados;
$sql  = new SqlInjection;
//===================================================================================================

$id  = @$sql->tratar($_GET['id'], 30);

//incluindo o arquivo do fpdf
include_once('../../includes/classes/fpdf/class.Fpdf.php');

//defininfo a fonte !
define('FPDF_FONTPATH','../../includes/classes/fpdf/font/');

//instancia a classe.. P=Retrato, mm =tipo de medida utilizada no casso milimetros, tipo de folha =A4

//define o TOP MARGIN
$pdf = new FPDF("L","mm","A4");

$pdf->SetTopMargin(15);
$pdf->SetLeftMargin(8);
$pdf->SetRightMargin(5);

//posicao vertical no caso -1.. e o limite da margem
$pdf->SetY("-1");

$data_ini		 		= @trim(strtoupper($_GET['data_ini']));
$data_fim 				= @trim(strtoupper($_GET['idcategoria']));

extract($_GET);	

$data_i = $data->getDataFormatada($data_ini);
$data_f = $data->getDataFormatada($data_fim);

//die($data_ini.'  : '.$data_fim);
	$titulo = utf8_decode('Relatório de Compromissos');
	
	$pdf->SetFont('arial','',10);
	$pdf->Cell(280,1,'','B',1,'C');
	$pdf->Ln(0);		
	
	$pdf->SetFont('arial','B',12);
	$pdf->Cell(280,5,$titulo,0,1,'C');
		
	$pdf->SetFont('arial','',10);
	$pdf->Cell(280,1,'','T',1,'C');
	$pdf->Ln(1);




//---------------------------------------------------------------------------------------------		
// SQL
//---------------------------------------------------------------------------------------------		

		
	extract($_GET);	
	$not->sql = " select compromissos.id, compromissos.nome, compromissos.data_m, compromissos.horario_inicial, compromissos.horario_final,
			compromissos.cliente_cad, compromissos.descricao
			from compromissos
			where compromissos.id is not null ";
				
	if($data_i != "" && $data_f != ""){
		$not->sql .= " and compromissos.data_m BETWEEN '".$data_i."' and '".$data_f."' ";
	}else if($data_i != ""){
		$not->sql .= " and compromissos.data_m like '%".$data_i."%' ";
	}
	//die($not->sql);		
		
	$pdf->SetX(10);
	$pdf->SetFont('arial','',9);
	$pdf->Cell(10,3,(utf8_decode('Nome evento')),0,0,'L');
	$pdf->Ln(0);
	
	$pdf->SetX(90);
	$pdf->SetFont('arial','',9);
	$pdf->Cell(90,3,(utf8_decode('Data marcada')),0,0,'L');
	$pdf->Ln(0);	
	
	$pdf->SetX(120);
	$pdf->SetFont('arial','',9);
	$pdf->Cell(120,3,(utf8_decode('Hora inicial')),0,0,'L');
	$pdf->Ln(0);			

	$pdf->SetX(150);
	$pdf->SetFont('arial','',9);
	$pdf->Cell(150,3,(utf8_decode('Hora final')),0,0,'L');
	$pdf->Ln(0);			

	$pdf->SetX(180);
	$pdf->SetFont('arial','',9);
	$pdf->Cell(180,3,(utf8_decode('Responsável')),0,0,'L');
	$pdf->Ln(0);
	
	
	$pdf->SetX(230);
	$pdf->SetFont('arial','',9);
	$pdf->Cell(230,3,(utf8_decode('Descrição')),0,1,'L');
	$pdf->Ln(2);			
	
	
	$pdf->SetFont('arial','',9);
	$pdf->Cell(280,1,'','T',1,'C');
	$pdf->Ln(1);				
		
//---------------------------------------------------------------------------------------------		
// PROCESSOS
//---------------------------------------------------------------------------------------------			
	if($not->ler()>0){					
		while($not->ini()){	
			$nome		 		   = $not->nome;
			$data_m  	   		   = $data->getDataFormatada($not->data_m);					
			$horario_inicial	   = $not->horario_inicial;
			$horario_final		   = $not->horario_final;
			$cliente_cad  		   = $not->cliente_cad;
			$descricao	  		   = $not->descricao;		
			
		
		$cont++;
		
		$pdf->SetX(10);
		$pdf->SetFont('arial','',8);
		$pdf->Cell(10,5,$nome,0,0,'L');
		$pdf->Ln(0);
		
		$pdf->SetX(90);
		$pdf->SetFont('arial','',8);
		$pdf->Cell(90,5,$data_m,0,0,'L');
		$pdf->Ln(0);	
		
		$pdf->SetX(120);
		$pdf->SetFont('arial','',8);
		$pdf->Cell(120,5,$horario_inicial,0,0,'L');
		$pdf->Ln(0);			
	
		$pdf->SetX(150);
		$pdf->SetFont('arial','',8);
		$pdf->Cell(150,5,$horario_final,0,0,'L');
		$pdf->Ln(0);			
	
		$pdf->SetX(180);
		$pdf->SetFont('arial','',8);
		$pdf->Cell(180,5,$cliente_cad,0,0,'L');
		$pdf->Ln(0);	
		

		$pdf->SetX(230);		
		$pdf->SetFont('arial','',8);					
		$y=0;
		$var_array = array();
		$vet_palavras = explode(' ',$descricao);					
		for($x=0;$x<count($vet_palavras);$x++){
				
			if(strlen($var_array[$y].$vet_palavras[$x]) <= 32)
				$var_array[$y] .= $vet_palavras[$x] . ' ';
			else
				$y++;																						
		
		}
		
		for($x=0;$x<count($var_array);$x++){
			
			$pdf->SetFont('arial','',8);
			$pdf->Cell(230,5,$var_array[$x],0,1,'L');	
			$pdf->Cell(222,5,'',0,0,'L');
			
		}		
		
		/*
		$pdf->SetX(230);
		$pdf->SetFont('arial','',8);
		$pdf->Cell(230,5,$descricao,0,1,'L');
		$pdf->Ln(0);		*/
		

		}
	
	}else{
		$pdf->SetFont('arial','B',12);
		$pdf->Cell(280,5,(utf8_decode('Nenhum dado foi encontrado.')),0,1,'C');			
	}
	if($cont == ""){
		$cont = 0;	
	}
	$pdf->Ln(2);		

	$pdf->SetFont('arial','B',10);
	$pdf->Cell(280,5,utf8_decode('Número de registros listados: ').$cont,'T',1,'C');
	$pdf->Ln(1);		
	
	$pdf->SetFont('arial','',10);
	$pdf->Cell(280,3,'','T',1,'C');
	
		
	$pdf->Output("relatorio_sintetico.pdf","D");
?>